/**
 *
 *      ___                       ___
 *     /\  \          ___        /\  \
 *    /::\  \        /\  \      /::\  \
 *   /:/\:\  \       \:\  \    /:/\ \  \
 *  /:/  \:\  \      /::\__\  _\:\~\ \  \
 * /:/__/ \:\__\  __/:/\/__/ /\ \:\ \ \__\
 * \:\  \  \/__/ /\/:/  /    \:\ \:\ \/__/
 *  \:\  \       \::/__/      \:\ \:\__\
 *   \:\  \       \:\__\       \:\/:/  /
 *    \:\__\       \/__/        \::/  /
 *     \/__/                     \/__/
 *
 * CIS - Clang Indexing Service is a Project Manager & Source code indexing service
 * created so as to simplify the indexing of C/C++ based source code which use
 * standardized build mechanisms.
 *
 **/

#ifndef COMPILATIONDB_HXX
#define	COMPILATIONDB_HXX

#include <string>
#include <vector>
#include <Poco/Thread.h>
#include <Poco/RunnableAdapter.h>
#include <Poco/HashMap.h>

namespace cis {

class Project;

class CompilationDB {
    typedef Poco::HashMap<std::string, std::string> FileFlagsMap;
private:
    std::string cdb;
    const Project& proj;
    Poco::Thread buildThread;
    Poco::RunnableAdapter<CompilationDB> runnable;
    FileFlagsMap fileFlagsMap;
    Poco::Mutex mtx;
    
    void buildOnThread();
    std::vector<std::string> getBuildParams();
    void load();
public:
    
    CompilationDB(const Project& proj);
    void build();
    std::string getFileFlags(const std::string& filename);
};

}

#endif	/* COMPILATIONDB_HXX */

